package com.educate.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * elasticsearch配置类
 * @author xiongyu
 * @date 2021/11/7 21:58
 */
@Configuration
@Component
public class ElasticSearchConfig {

    /**
     * 请求地址
     */
    @Value("${elasticsearch.url}")
    public String elasticsearchURL;

    /**
     * 注册elasticsearch客户端对象
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(RestClient.builder(HttpHost.create(elasticsearchURL)));
    }
}
